<?php

	// TITLE: Monies AUTO MODEL
	// FILE: scaffolding/model/monies.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createMonies = function($con, $monies) {
		$sql = 'INSERT INTO monies (donation_id, amount, method, date) VALUES (';
		$sql .= $monies->getDonationId() . ', ';
		$sql .= $monies->getAmount() . ', ';
		$sql .= $monies->getMethod() . ', ';
		$sql .= $monies->getDate() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readMonies = function($con, $id) {
		$sql = 'SELECT * FROM monies WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$monies = new Monies();
			$monies->setDonationId($dbio->select($readDonation(result[0])));
			$monies->setAmount(result[1]);
			$monies->setMethod(result[2]);
			$monies->setDate(result[3]);
		} else {
			$monies = false;
		}
		return $monies;
	};

	$updateMonies = function($con, $monies) {
		$sql = 'UPDATE monies SET ';
		$sql .= 'donation_id = ' . $monies->getDonationId() . ', ';
		$sql .= 'amount = ' . $monies->getAmount() . ', ';
		$sql .= 'method = ' . $monies->getMethod() . ', ';
		$sql .= 'date = ' . $monies->getDate() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteMonies = function($con, $id) {
		$sql = 'DELETE FROM monies WHERE donation_id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listMonies = function($con) {
		$sql = 'SELECT * FROM monies';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$moniess = array();
			while ($result = mysqli_fetch_array($results)) {
				$monies = new Monies();
				$monies->setDonationId($dbio->select($readDonation(result[0])));
				$monies->setAmount(result[1]);
				$monies->setMethod(result[2]);
				$monies->setDate(result[3]);
				$moniess[] = monies;
			}// end while
		} else {
			$moniess = false;
		}
		return $moniess;
	};

